function Get-IISWebSiteUrl([string]$name)
{
    # Write-Host $name
    [string[]] $site = @()
    (Get-Website $name).bindings.Collection | foreach {
        $bindingTokens = $_.bindingInformation -split ':'
        $siteHost = ''
        $port = ''
        $protocol = $_.protocol

        if($bindingTokens[2] -ne '')
        {
            $siteHost = $bindingTokens[2]
        }elseif ($bindingTokens[0] -ne '*') {
            $siteHost = $bindingTokens[0]
        }else {
            $siteHost = [net.dns]::GetHostAddresses('') |
            where { $_.AddressFamily -eq 'InterNetwork'} |
            select -ExpandProperty IPAddressToString -First 1
        }

        if($bindingTokens[1] -eq '80') { $port = '' }
        else { $port = ':' + $bindingTokens[1] }

        $site = $site + ('{0}://{1}{2}' -f $protocol,$siteHost,$port)

    }

    $site
}

# Powershell 脚本调用方法

# 方法一： 
# Get-Content "D:\PowershellScripts\Test\ErrorMailNotice.ps1" | Invoke-Expression

# 方法二：
# $script = "D:\PowershellScripts\Test\ErrorMailNotice.ps1"
# .$script